package com.shop.goods.controller;

import com.shop.domain.Classify;
import com.shop.entity.Result;
import com.shop.goods.service.ClassifyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品分类
 */
@RestController
@RequestMapping("/Classify")
@CrossOrigin
public class ClassifyController {
    @Autowired
    private ClassifyService classifyService;
    /**
     * 查询全部分类表
     * @param
     * @return
     */
    @GetMapping("/selectAll")
    public Result<List<Classify>> selectAll(){
        return new Result<>("查询成功",classifyService.selectAll());
    }
    /**
     * 新增分类表
     * @param iClassify
     * @return
     */
    @PostMapping("/insert")
    public Result insert(@RequestBody Classify iClassify){
        classifyService.insert(iClassify);
        return new Result<>("新增成功");
    }
    /**
     * 修改分类表
     * @param classify
     * @return
     */
    @PostMapping("/update")
    public Result update(@RequestBody Classify classify){
        classifyService.update(classify);
        return new Result<>("修改成功");
    }
    /**
     * 删除分类表
     * @param id
     * @return
     */
    @GetMapping("/delete")
    public Result delete(@RequestParam Integer id){
        if(classifyService.delete(id)==-1){
            return new Result("删除失败");
        }
        return new Result<>("删除成功");
    }



}
